package com.aifast.system.sys.controller;


import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.stp.StpUtil;
import cn.hutool.core.lang.Console;
import cn.hutool.core.thread.ThreadUtil;
import com.aifast.common.annotations.AiIdempotent;
import com.aifast.common.base.R;
import com.aifast.common.layui.LayuiDataTable;
import com.aifast.system.util.UserUtil;
import com.aifast.system.sys.entity.SysRole;
import com.aifast.system.sys.service.SysRoleService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.aifast.common.base.Controller;
/**
 * <p>
 * 角色表 前端控制器
 * </p>
 *
 * @author fujian
 * @since 2021-12-30
 */
@RequiredArgsConstructor
@RestController
@RequestMapping("/sys/sysRole")
public class SysRoleController extends Controller {

    private final SysRoleService sysRoleService;

    @SaCheckPermission("role:list")
    @GetMapping("list")
    public LayuiDataTable list() {
        return sysRoleService.list(get("search"), getInt("permissionType"), getPage());
    }

    @AiIdempotent
    @SaCheckPermission("role:addOrUpdate")
    @PostMapping("add")
    public R add(SysRole role) {
        return sysRoleService.insertOrUpdate(role) ? OK() : ERROR();
    }

    @AiIdempotent
    @SaCheckPermission("role:del")
    @GetMapping("del")
    public R del() {
        return sysRoleService.del(getInt("id"), get("ids")) ? OK() : ERROR();
    }

    @SaCheckPermission("role:list")
    @GetMapping("info")
    public R info() {
        return sysRoleService.info(getInt("id"));
    }

    @GetMapping("info1")
    public R info1() {
        return sysRoleService.info1(getInt("id"));
    }

    @GetMapping("selectData")
    public R selectData(){
        return OK(sysRoleService.list());
    }


}

